package org.jeecg.modules.aop;

import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.modules.message.websocket.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 下单成功通知切面
 */
@Aspect
@Component
public class OrderNotifyAspect {

    @Autowired
    private ISysBaseAPI sysBaseAPI;

    @Pointcut("execution (* org.jeecg.modules.order.controller.BusOrderController.add(..))")
    public void order() {
    }

    @AfterReturning(value = "order()", returning = "returnObject")
    public void afterAdvice(JoinPoint joinPoint, Object returnObject) {
        System.out.println("开始发送消息...");
        //创建业务消息信息
        JSONObject obj = new JSONObject();
        obj.put("cmd", "topic");//业务类型
        obj.put("msgId", "1416277930178224129");//消息id

//多个用户发送 (userIds为多个用户id，逗号‘,’分隔)
        sysBaseAPI.sendWebSocketMsg(new String[]{"e9ca23d68d884d4ebb19d07889727dae"}, obj.toJSONString());
    }
}
